package com.learn.mvc.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class Demo05HandlerAndCookieHandler {
    Logger logger = LoggerFactory.getLogger(this.getClass());
    @RequestMapping("/request/header")
    public String getRequestHeader(
            // 使用 RequestParam 注解获取请求消息头
            @RequestHeader(value = "accept", defaultValue = "missing") String accept,
            @RequestHeader(value = "cookie", defaultValue = "missing") String cookie,
            HttpSession session
    ) {
        logger.debug(accept);
        logger.debug(cookie);

        return "target";
    }

    @RequestMapping("/request/cookie")
    public String getCookie(
            @CookieValue(value = "JSESSIONID", defaultValue = "missing") String cookieValue,
            // 形参位置声明 HttpSession 类型的参数 即可获取HttpSession 这个对象
            HttpSession session
    ) {
        logger.debug("cookieValue = " + cookieValue);
        return "target";
    }
}
